<%--
  Created by IntelliJ IDEA.
  User: 29276
  Date: 2021/8/23
  Time: 21:57
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    //http://localhost:8080/01_sxtoa_war_exploded/
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <base href="<%=basePath%>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="css/select.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="js/jquery.js"></script>

    <script type="text/javascript" src="js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="js/select-ui.min.js"></script>
    <script type="text/javascript" src="editor/kindeditor.js"></script>
    <script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(document).ready(function(e) {
            $(".select1").uedSelect({
                width : 150
            });

        });
    </script>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".click").click(function(){
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function(){
                $(".tip").fadeOut(200);
            });

            $(".sure").click(function(){
                $(".tip").fadeOut(100);
            });

            $(".cancel").click(function(){
                $(".tip").fadeOut(100);
            });

        });
    </script>

    <script type="text/javascript">
        $(function () {
            $.post("deptServlet", {methodName:"deptList"}, function (data) {
                if (data === "sessionTimeOut") {
                    window.location.href="login.jsp";
                    return;
                }
                eval("var ds="+data);
                var deptSelect = $("#deptSelect");
                for (var i = 0; i < ds.length; i++) {
                    deptSelect.append("<option value='"+ds[i].deptNo+"'>"+ds[i].deptName+"</option>");
                }
            })
        })



        $(function () {
            var pNum = 1;
            var pSize = 2;
            var pages;

            $("#find").click(function () {
                ajaxPage(1, pSize);
            })

            $("#pageUp").click(function () {
                console.log("上一页");
                console.log(pNum);
                if (pNum !== 1) {
                    pNum = ajaxPage(--pNum, pSize);
                } else {
                    alert("当前是第一页");
                }
                console.log("返回值："+ pNum);
            })

            $("#pageDown").click(function () {
                console.log("下一页");
                console.log(pNum);
                if (pNum !== pages) {
                    pNum = ajaxPage(++pNum, pSize);
                } else {
                    alert("当前是最后一页");
                }
                console.log("返回值："+ pNum);
            })

            pNum = ajaxPage(1, pSize);
            function ajaxPage(pNum, pSize) {
                const reqData = {
                    methodName: "expenseList",
                    pageNum: pNum,
                    pageSize: pSize,
                    startDate: $("#startDate").val(),
                    endDate: $("#endDate").val(),
                    deptNo: $("#deptSelect").val(),
                    realName: $("#realName").val()

                };
                $.post("incomeServlet", reqData, function (data) {
                    if (data === "sessionTimeOut") {
                        window.location.href="login.jsp";
                        return;
                    }
                    console.log(data);
                    eval("var result="+data);
                    var ds = result.list;
                    pages = result.pages;
                    var totle = result.size;

                    $("#total").html(totle);
                    $("#pageNum").html(pNum);

                    $("#pageUl>li:not(#pageUp,#pageDown)").remove();
                    for (var i = 1; i <= pages; i++) {
                        $("#pageDown").before("<li class=\"paginItem\"><a class='page' id='"+i+"' href=\"javascript:void(0);\">"+i+"</a></li>");
                    }
                    $(".page").click(function () {
                        console.log("点击数字：" + this.id);
                        console.log(this.id);
                        pNum = this.id;
                        console.log(pNum);
                        pNum = ajaxPage(pNum, pSize);
                        console.log("返回值："+ pNum);
                        return pNum;
                    })
                    const tb = $("#tb");
                    tb.empty();
                    for (i = 0; i < ds.length; i++) {
                        tb.append("<tr>\n" +
                            "            <td>\n" +
                            "                <input name=\"\" type=\"checkbox\" value=\"\" />\n" +
                            "            </td>\n" +
                            "            <td>" + ds[i].realName + "</td>\n" +
                            "            <td>" + ds[i].totalAmount + "</td>\n" +
                            "            <td>" + ds[i].expTime + "</td>\n" +
                            "            <td>" + ds[i].deptName + "</td>\n" +
                            "            <td>" + ds[i].expDesc + "</td>\n" +
                            "            <td><a href=\"income/expenseDetail.jsp?expId="+ds[i].expId+"\" class=\"tablelink\"> 查看</a></td>\n" +
                            "             </td>\n" +
                            "        </tr>");
                    }
                })
                return pNum;
            }
        })

    </script>


</head>

<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">收支管理</a></li>
        <li><a href="#">查看支出</a></li>
    </ul>
</div>

<div class="rightinfo">

    <ul class="prosearch">
        <li>
            <label>查询：</label>
            <i>起始登记时间</i>
            <a>
                <input id="startDate" name="" type="text" class="scinput" onfocus="WdatePicker()" />
            </a>
            <i>结束登记时间</i>
            <a>
                <input id="endDate" name="" type="text" class="scinput" onfocus="WdatePicker()" />
            </a>
            <i>支出人</i>
            <a>
                <input id="realName" name="" type="text" class="scinput" />
            </a>
            </a><i>部门</i>
            <a>
                <select id="deptSelect" name="deptNo" class="select1">
                    <option value="">所有</option>
                </select>
            </a>
            <a>
                <input id="find" name="" type="button" class="sure" value="查询" />
            </a>

        </li>
    </ul>

    <div class="formtitle1"><span>支出列表</span></div>

    <table class="tablelist">
        <thead>
        <tr>
            <th>
                <input name="" type="checkbox" value="" checked="checked" />
            </th>
            <th>支出人</th>
            <th>金额</th>
            <th>支出时间</th>
            <th>所属部门</th>
            <th>备注</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tb">

        </tbody>
    </table>

    <div class="pagin">
        <div class="message">共<i id="total" class="blue"></i>条记录，当前显示第&nbsp;<i id="pageNum" class="blue">&nbsp;</i>页</div>
        <ul id="pageUl" class="paginList">
            <li class="paginItem" id="pageUp"><a href="javascript:;"><span class="pagepre"></span></a></li>
            <li class="paginItem" id="pageDown"><a href="javascript:;"><span class="pagenxt"></span></a></li>
        </ul>
    </div>

    <div class="tip">
        <div class="tiptop"><span>提示信息</span>
            <a></a>
        </div>

        <div class="tipinfo">
            <span><img src="images/ticon.png" /></span>
            <div class="tipright">
                <p>是否确认对信息的修改 ？</p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
            </div>
        </div>

        <div class="tipbtn">
            <input name="" type="button" class="sure" value="确定" />&nbsp;
            <input name="" type="button" class="cancel" value="取消" />
        </div>

    </div>

</div>

<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
</script>

</body>

</html>
